package nc.arap.pub.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;

public class VoucherUtils {
	public static String getOracleSQLIn(List<String> list, int count,
			String field) {
		count = Math.min(count, 1000);
		int len = list.size();
		int size = len % count;
		if (size == 0) {
			size = len / count;
		} else {
			size = (len / count) + 1;
		}
		StringBuilder builder = new StringBuilder();
		for (int i = 0; i < size; i++) {
			int fromIndex = i * count;
			int toIndex = Math.min(fromIndex + count, len);
			String productId = StringUtils.defaultIfEmpty(
					StringUtils.join(
							list.subList(fromIndex, toIndex).toArray(
									new String[0]), "','"), "");
			if (i != 0) {
				builder.append(" or ");
			}
			builder.append(field).append(" in ('").append(productId)
					.append("')");
		}
		return StringUtils.defaultIfEmpty(builder.toString(), field
				+ " in ('')");
	}
	
	public static String getOracleSQLIn(Set<String> list, int count,
			String field) {

			List<String> result = new ArrayList<>(list);
			return getOracleSQLIn(result, count, field);
	}

}
